package com.swt.controller.T_controller;

import com.alibaba.fastjson.JSON;
import com.swt.domain.Club;
import com.swt.domain.Courses;
import com.swt.service.T_service.CurriculumService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class Curriculum {
    @Resource
    private CurriculumService curriculumService;


@RequestMapping("/addCurriculum")
@ResponseBody
    public  String add (String name,String addcalorie,String addGrade,String addType,String addIntro,String imgPWT,HttpServletRequest httpServletRequest){

    Club club = (Club) httpServletRequest.getSession().getAttribute("CLUB_SESSION_KEY");
    int clubClubId = club.getClubId();

        boolean result = curriculumService.addCurriculum(name,addcalorie,addGrade,addType,addIntro,imgPWT,clubClubId);
        System.out.println(result+"=====结果====");
        return JSON.toJSONString(result);
    }

@RequestMapping("/query1Curriculum")
@ResponseBody
    public String query(int page,HttpServletRequest httpServletRequest){
    Club club = (Club) httpServletRequest.getSession().getAttribute("CLUB_SESSION_KEY");
    int clubClubId = club.getClubId();

     List<Courses> coursesList = curriculumService.crriculumquery1(page,clubClubId);
    System.out.println(JSON.toJSONString(coursesList)+"=============");
     return JSON.toJSONString(coursesList);

    }

    @RequestMapping("/query2Curriculum")
    @ResponseBody
    public String query2(int id,HttpServletRequest httpServletRequest){
        Club club = (Club) httpServletRequest.getSession().getAttribute("CLUB_SESSION_KEY");
        int clubClubId = club.getClubId();
    List<Courses> coursesList = curriculumService.crriculumquery2(id,clubClubId);
        System.out.println(JSON.toJSONString(coursesList)+"=============");
        return JSON.toJSONString(coursesList);

    }

    @RequestMapping("/deleteCurriculum")
    @ResponseBody
    public String deleteCurriculum(int id){

        boolean bo = curriculumService.deleteCulum(id);
        System.out.println(JSON.toJSONString(bo)+"=============");
        return JSON.toJSONString(bo);

    }

    @RequestMapping("/updateCurriculum")
    @ResponseBody
    public String updateCurriculum(Courses courses){

        boolean updatecrriculum  =curriculumService.updatecrriculum(courses);
        int coursesid  = courses.getCoursesid();
        System.out.println(updatecrriculum);

        return JSON.toJSONString(updatecrriculum);

    }

//向排课页面发送课程信息
    @RequestMapping("/queryCoursesPK")
    @ResponseBody
    public String queryCoursesPK(HttpServletRequest httpServletRequest){
        Club club = (Club) httpServletRequest.getSession().getAttribute("CLUB_SESSION_KEY");
        int clubClubId = club.getClubId();

        List<Courses> coursesList = curriculumService.queryCoursesPK1(clubClubId);
        System.out.println(JSON.toJSONString(coursesList)+"=============");
        return JSON.toJSONString(coursesList);

    }





    public CurriculumService getCurriculumService() {
        return curriculumService;
    }

    public void setCurriculumService(CurriculumService curriculumService) {
        this.curriculumService = curriculumService;
    }
}
